/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datos;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;

/**
 *
 * @author oza
 */
public class OperacionesBase {

    DatabaseManager db = new DatabaseManager();

    public ResultSet callProcedure(CallableStatement stmt) throws SQLException {
        stmt.execute();
        ResultSet resultado = (ResultSet) stmt.getObject(1);
        return resultado;
    }

    public boolean ingreso(String query) throws SQLException {
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        boolean resultado = false;
        try {
            resultado = stmt.execute(query);
            
        } catch (Exception e) {
            return false;
        }
        var.commit();
        return resultado;
    }

    public ResultSet seleccion(String query) throws SQLException {
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        ResultSet resultado = stmt.executeQuery(query);
        var.commit();
        return resultado;
    }

    public int modificacioneliminacion(String query) throws SQLException {
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        int resultado = stmt.executeUpdate(query);
        var.commit();
        return resultado;
    }

    public Connection reporte() {
        Connection c = db.getConnection();

        return c;
    }

    public void cerrarConexion() throws SQLException {
        db.getConnection().close();
    }

    public ResultSet busPrenda(String query) throws SQLException {
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        ResultSet resultado = stmt.executeQuery(query);
        var.commit();
        return resultado;
    }
    
    public boolean ingreso2(String query) throws SQLException {
        Connection var = db.getConnection();
        Statement stmt = var.createStatement();
        boolean resultado = false;
        try {
            resultado = stmt.execute(query);
            
        } catch (Exception e) {
            return false;
        }
        var.commit();
        return true;
    }
}
